package com.nopay.cdxphone.ui.ativity;

import android.os.Bundle;

import com.nopay.cdxphone.base.BaseActivity;
import com.ycbjie.webviewlib.inter.InterWebListener;
import com.ycbjie.webviewlib.utils.ToastUtils;
import com.ycbjie.webviewlib.utils.X5WebUtils;
import com.nopay.cdxphone.R;
import com.nopay.cdxphone.databinding.ActivityComputerImportCourseBinding;

public class ComputerImportCourseActivity extends BaseActivity<ActivityComputerImportCourseBinding> {

    private static final String URL = "http://www.jd.com";

    @Override
    protected void init(Bundle savedInstanceState, Object... preData) {
        binding.rlRoot.setPadding(0, getStatusBarHeight(ComputerImportCourseActivity.this), 0, 0);
        binding.ivBack.setOnClickListener(v -> mSwipeBackHelper.backward());

        binding.progress.show();
        binding.progress.setColor(this.getResources().getColor(R.color.colorAccent),this.getResources().getColor(R.color.colorPrimaryDark));

        binding.webView.loadUrl(URL);
        binding.webView.getX5WebChromeClient().setWebListener(interWebListener);
        binding.webView.getX5WebViewClient().setWebListener(interWebListener);
        if (!X5WebUtils.isConnected(this)){
            ToastUtils.showRoundRectToast("请先连接上网络");
        }

        // 微信分享
        binding.tvWxShare.setOnClickListener(v -> {
            // todo 微信分享
        });
    }

    private final InterWebListener interWebListener = new InterWebListener() {
        @Override
        public void hindProgressBar() {
            binding.progress.hide();
        }

        @Override
        public void showErrorView(@X5WebUtils.ErrorType int type) {
            switch (type){
                //没有网络
                case X5WebUtils.ErrorMode.NO_NET:
                    break;
                //404，网页无法打开
                case X5WebUtils.ErrorMode.STATE_404:

                    break;
                //onReceivedError，请求网络出现error
                case X5WebUtils.ErrorMode.RECEIVED_ERROR:

                    break;
                //在加载资源时通知主机应用程序发生SSL错误
                case X5WebUtils.ErrorMode.SSL_ERROR:

                    break;
                default:
                    break;
            }
        }

        @Override
        public void startProgress(int newProgress) {
            binding.progress.setWebProgress(newProgress);
        }

        @Override
        public void showTitle(String title) {

        }
    };
}
